﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using System.Data;

namespace Qpm.Automap.Core
{
  public static class XlReader
  {
    public static DataSet ReadXlFile(string fileName)
    {
      string xlsxConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source={0}; Extended Properties=Excel 12.0; HDR=YES";
      string connstring = string.Format(xlsxConnectionString, fileName);

      OleDbConnection conn = new OleDbConnection(connstring);
      try
      {
        conn.Open();
        OleDbCommand cmd = new OleDbCommand("Select * From [Sheet1$]", conn);
        OleDbDataAdapter da = new OleDbDataAdapter();

        da.SelectCommand = cmd;

        DataSet ds = new DataSet();

        da.Fill(ds);

        return ds;
      }
      catch (Exception ex)
      {
        throw ex;
      }
    }
  }
}
